package com.swlz.servlet.user;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;

import com.swlz.R;
import com.swlz.dto.MallOrderDetailSearch;
import com.swlz.entity.MallOrder;
import com.swlz.entity.User;
import com.swlz.service.AreasService;
import com.swlz.service.MallOrderDetailService;
import com.swlz.service.MallOrderService;
import com.swlz.service.UserService;
import com.swlz.service.impl.AreasServiceImpl;
import com.swlz.service.impl.MallOrderDetailServiceImpl;
import com.swlz.service.impl.MallOrderServiceImpl;
import com.swlz.service.impl.UserServiceImpl;
import com.swlz.servlet.HttpServletSupport;
import com.swlz.vo.LoginUser;

@WebServlet("/user/order.let")
public class OrderServlet extends HttpServletSupport {

	private MallOrderService service = new MallOrderServiceImpl();
	private MallOrderDetailService detailService = new MallOrderDetailServiceImpl();
	private UserService userService = new UserServiceImpl();
	private AreasService areasService = new AreasServiceImpl();
	
	public Object execute(LoginUser user,HttpServletRequest request)throws Exception {
		int current = 1;
		int rowMax = 10;
		try {
			current = Integer.valueOf(request.getParameter("pageNumber"));
		}catch (Exception e) {
		}
		try {
			rowMax = Integer.valueOf(request.getParameter("pageSize"));
		}catch (Exception e) {
		}
		MallOrder mallOrder = new MallOrder();
		mallOrder.setOrderStatus(Integer.valueOf(request.getParameter("status")));
		mallOrder.setUserId(user.getUserId());
		return service.page(mallOrder, current, rowMax);
	}
	
	public Object get(HttpServletRequest request) {
		MallOrder order = service.get(Long.valueOf(request.getParameter("id")));
		User user = userService.get(order.getUserId());
		String address = areasService.getName(order.getOrderAddressCode());
		return R.map()
				.push("order", order)
				.push("userName", user.getUserName())
				.push("userNickname", user.getUserNickname())
				.push("address", address);
	}
	
	public Object page(MallOrderDetailSearch search)throws Exception {
		return detailService.page(search);
	}
	

}
